﻿using System.Linq.Expressions;
using SqlSugar;

namespace WeDonekRpc.SqlSugar
{
    public interface ISqlQueue<T> where T : class, new()
    {
        /// <summary>
        /// 是否为空队列
        /// </summary>
        bool IsNull { get; }

        #region 删除数据
        /// <summary>
        /// 根据条件删除
        /// </summary>
        /// <param name="filter"></param>
        void Delete ( Expression<Func<T, bool>> filter );

        /// <summary>
        /// 链表删除数据
        /// </summary>
        /// <typeparam name="Other">另外一个表</typeparam>
        /// <param name="filter"></param>
        void Delete<Other> ( Expression<Func<T, Other, bool>> filter ) where Other : class, new();

        /// <summary>
        /// 删除指定表的数据
        /// </summary>
        /// <typeparam name="Table"></typeparam>
        /// <param name="filter"></param>
        void DeleteBy<Table> ( Expression<Func<Table, bool>> filter ) where Table : class, new();

        /// <summary>
        /// 获取删除对象
        /// </summary>
        /// <returns></returns>
        IDeleteable<T> Delete ();

        /// <summary>
        /// 删除所有
        /// </summary>
        void DeleteAll ();

        #endregion

        #region 添加数据
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="item"></param>
        void Insert ( T item );
        /// <summary>
        /// 插入多条数据
        /// </summary>
        /// <param name="items"></param>
        void Insert ( T[] items );

        /// <summary>
        /// 插入多条数据
        /// </summary>
        /// <param name="items"></param>
        void Insert ( List<T> items );
        /// <summary>
        /// 插入其它表的数据
        /// </summary>
        /// <typeparam name="Table"></typeparam>
        /// <param name="item"></param>
        void InsertBy<Table> ( Table item ) where Table : class, new();

        /// <summary>
        /// 插入多条其它表的数据
        /// </summary>
        /// <typeparam name="Table"></typeparam>
        /// <param name="items"></param>
        void InsertBy<Table> ( Table[] items ) where Table : class, new();

        /// <summary>
        /// 插入多条其它表的数据
        /// </summary>
        /// <typeparam name="Table"></typeparam>
        /// <param name="items"></param>
        void InsertBy<Table> ( List<Table> items ) where Table : class, new();
        #endregion

        #region 修改数据

        /// <summary>
        /// 只能修改单列
        /// </summary>
        /// <param name="columns"></param>
        /// <param name="data"></param>
        void Update ( T data, Expression<Func<T, object>> columns );

        void Update ( Expression<Func<T, T>> columns, Expression<Func<T, bool>> filter );

        void Update ( T data, Expression<Func<T, bool>> filter );

        /// <summary>
        /// 获取当前修改对象
        /// </summary>
        /// <returns></returns>
        IUpdateable<T> Update ();

        void Update ( T data, params string[] setColumn );

        void Update ( T data, string[] setColumn, Expression<Func<T, bool>> filter );

        void UpdateOnly ( T[] datas, Expression<Func<T, object>> setCol );

        bool Update ( T source, T set );

        void Update ( T[] datas, params string[] setColumn );

        void Update<Set> ( Set set, Expression<Func<T, bool>> filter );

        bool Update<Set> ( T source, Set set );

        void Update ( T[] datas, Expression<Func<T, object>> filter );

        void UpdateOneColumn ( Expression<Func<T, bool>> columns, Expression<Func<T, bool>> filter );

        #endregion


        #region 修改其它表数据

        /// <summary>
        /// 只能修改单列
        /// </summary>
        /// <param name="columns"></param>
        /// <param name="data"></param>
        void UpdateBy<Table> ( Table data, Expression<Func<Table, object>> columns ) where Table : class, new();

        void UpdateBy<Table> ( Expression<Func<Table, Table>> columns, Expression<Func<Table, bool>> filter ) where Table : class, new();

        void UpdateBy<Table> ( Table data, Expression<Func<Table, bool>> filter ) where Table : class, new();

        void UpdateBy<Table> ( Table data, params string[] setColumn ) where Table : class, new();

        void UpdateBy<Table> ( Table data, string[] setColumn, Expression<Func<Table, bool>> filter ) where Table : class, new();

        void UpdateByOnly<Table> ( Table[] datas, Expression<Func<Table, object>> setCol ) where Table : class, new();

        bool UpdateBy<Table> ( Table source, Table set ) where Table : class, new();

        void UpdateBy<Table> ( Table[] datas, params string[] setColumn ) where Table : class, new();

        void UpdateBy<Table, Set> ( Set set, Expression<Func<Table, bool>> filter ) where Table : class, new();

        bool UpdateBy<Table, Set> ( Table source, Set set ) where Table : class, new();

        void UpdateBy<Table> ( Table[] datas, Expression<Func<Table, object>> filter ) where Table : class, new();

        void UpdateByOneColumn<Table> ( Expression<Func<Table, bool>> columns, Expression<Func<Table, bool>> filter ) where Table : class, new();

        #endregion
        Task<int> SubmitAsync ( bool isTran = true );
        int Submit ( bool isTran = true );
    }
    public interface ISqlQueue
    {
        /// <summary>
        /// 是否为空队列
        /// </summary>
        bool IsNull { get; }
        /// <summary>
        /// 只能修改单列
        /// </summary>
        /// <typeparam name="Set"></typeparam>
        /// <param name="columns"></param>
        /// <param name="filter"></param>
        void Update<Set> ( Expression<Func<Set, bool>> columns, Expression<Func<Set, bool>> filter ) where Set : class, new();
        IUpdateable<T> Update<T> () where T : class, new();
        IDeleteable<T> Delete<T> () where T : class, new();
        void Delete<T> ( Expression<Func<T, bool>> filter ) where T : class, new();
        void Delete<T, Other> ( Expression<Func<T, Other, bool>> filter ) where Other : class, new() where T : class, new();
        void Insert<T> ( T item ) where T : class, new();
        void Insert<T> ( T[] items ) where T : class, new();
        void Insert<Table> ( List<Table> items ) where Table : class, new();
        void Update<T> ( Expression<Func<T, T>> columns, Expression<Func<T, bool>> filter ) where T : class, new();
        void UpdateOneColumn<T> ( Expression<Func<T, bool>> columns, Expression<Func<T, bool>> filter ) where T : class, new();
        void Update<T> ( T data, Expression<Func<T, object>> columns ) where T : class, new();
        void Update<T> ( T data, string[] setColumn ) where T : class, new();
        void Update<T> ( T data, string[] setColumn, Expression<Func<T, bool>> filter ) where T : class, new();
        bool Update<T> ( T source, T set ) where T : class, new();
        void DeleteAll<T> () where T : class, new();
        void Update<T> ( T[] datas, params string[] setColumn ) where T : class, new();
        void Update<T, Set> ( Set set, Expression<Func<T, bool>> filter ) where T : class, new();
        bool Update<T, Set> ( T source, Set set ) where T : class, new();

        Task<int> SubmitAsync ( bool isTran = true );
        int Submit ( bool isTran = true );
    }
}